package org.vestbjergbyggecenter.TUI;

import java.util.Scanner;

import org.vestbjergbyggecenter.Controller.CategoryCtr;

public class CategoryMenu {
	private CategoryCtr categoryCtr;
    private static CategoryMenu instance = null;
	
    private CategoryMenu()
    {
        categoryCtr = CategoryCtr.getInstance();
        start();
    }
    
    public static CategoryMenu getInstance()
    {
        if(instance == null)
        {
            instance = new CategoryMenu();
        }
        return instance;
    }
    
    // start menu
    public void start()
    {
        boolean exit = false;
        while(!exit)
        {
            int choice = printCategoryMenu();
            switch (choice)
            {
                case 1: listAllCategories();
                        break;
                case 2: printCategory();
                        break;
                case 3: createCategory();
                        break;
                case 4: updateCategory();
        				break;
                case 5: deleteCategory();
                		break;
                case 6: goBack();
                		break;
            }
        }
    }	    
    
  //print menu
    public int printCategoryMenu()
    {
        Scanner keyboard = new Scanner(System.in);
        //System.out.print('\f');
        System.out.println("***Category Menu***");
        System.out.println("1. List all categories");
        System.out.println("2. Print particular category");
        System.out.println("3. Register new category");
        System.out.println("4. Update category");
        System.out.println("5. Delete Category"); 
        System.out.println("6. Go back");
        System.out.println("Choice #: ");
        
        int choice = keyboard.nextInt();        
        return choice;
   }
    
    //1
    //prints all the categories
    public void listAllCategories()
    {
    	CategoryCtr.getInstance().printCategories();
    }
    
    //2
    //print a particular category by selecting its title
    public void printCategory()
    {
    	Scanner keyboard = new Scanner(System.in); 
    	System.out.println('\f');
    	
    	System.out.println("Input category title: ");
    	String categoryTitle=keyboard.nextLine();
    	
    	categoryCtr.printCategory(categoryTitle);    	
    }
    
    //3
    //register a new category
    public void createCategory()
    {
    	Scanner keyboard = new Scanner(System.in); 
    	System.out.println('\f');
    	
    	System.out.println("Input category new title: ");
    	String categoryTitle=keyboard.nextLine();
    	
    	System.out.println("Input category new discount: ");
    	double categoryDiscount=keyboard.nextDouble();
    	
    	categoryCtr.createCategory(categoryTitle, categoryDiscount);
    	
    }

    //4
    //update a category
    public void updateCategory()
    {
    	Scanner keyboard = new Scanner(System.in); 
    	System.out.println('\f');
    	
    	System.out.println("Input category title: ");
    	String categoryWantedTitle=keyboard.nextLine();
    	
    	System.out.println("Input category new title: ");
    	String categoryTitle=keyboard.nextLine();
    	
    	System.out.println("Input category new discount: ");
    	double categoryDiscount=keyboard.nextDouble();
    	
    	
    	categoryCtr.updateCategory(categoryWantedTitle, categoryTitle, categoryDiscount);
    }
    
    //5
    //delete a category
    public void deleteCategory()
    {
    	Scanner keyboard = new Scanner(System.in); 
    	System.out.println('\f');
    	
    	System.out.println("Input category title: ");
    	String categoryWantedTitle=keyboard.nextLine();
    	
    	
    	categoryCtr.deleteCategory(categoryWantedTitle);
    }
    
 // calls and returns to main menu
    public void goBack()
    {
        MainMenu.getInstance().start();
    }

}
